/* 
This do file combines the output from the simulations into "Simulation_Results_all"

NOTES: All directories and paths should be set in the "Reallocation_master.do" file.

*/

clear all

use `"${data_intermediate}/Simulation_Results_Country"'

keep zipcode NAME STATE num_systems new_num_systems new_num_systems30
rename num_systems original_systems
rename new_num_systems interstate_env
rename new_num_systems30 interstate_env30

merge 1:1 zipcode using `"${data_intermediate}/Simulation_Results_Intrastate"'
keep zipcode NAME STATE original_systems interstate_env interstate_env30 state_new_num_systems state_new_num_systems30
rename state_new_num_systems intrastate_env
rename state_new_num_systems30 intrastate_env30

merge 1:1 zipcode using `"${data_intermediate}/Simulation_Results_Country_energy_plus_env"'
keep zipcode NAME STATE original_systems interstate_env interstate_env30 intrastate_env intrastate_env30 new_num_systems new_num_systems30
rename new_num_systems interstate_env_energy
rename new_num_systems30 interstate_env_energy30

merge 1:1 zipcode using `"${data_intermediate}/Simulation_Results_Intrastate_energy_plus_env"'
keep zipcode NAME STATE original_systems interstate_env interstate_env30 intrastate_env intrastate_env30 interstate_env_energy interstate_env_energy30 state_new_num_systems state_new_num_systems30
rename state_new_num_systems intrastate_env_energy
rename state_new_num_systems30 intrastate_env_energy30

save `"${data_intermediate}/Simulation_Results_all"', replace
outsheet zipcode NAME STATE original_systems interstate_env interstate_env30 intrastate_env intrastate_env30 interstate_env_energy interstate_env_energy30 intrastate_env_energy intrastate_env_energy30 using `"${data_intermediate}/Simulation_Results_all.csv"', comma replace
